package com.metersbonwe.basetest.proxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import org.junit.Test;

import com.metersbonwe.basetest.core.TestClient;

public class TestTaskMethodInterceptor implements MethodInterceptor {

	public TestClient testClient;

	public TestTaskMethodInterceptor(TestClient testClient) {
		this.testClient = testClient;
	}

	public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		Test test = method.getAnnotation(Test.class);
		if (test != null) {
			testClient.run();
			return null;
		}
		return proxy.invokeSuper(obj, args);
	}
}
